package demo1;
import java.util.*;


/*
public class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}*/
public class PalindromeList {
    public boolean chkPalindrome(ListNode A) {
        // write code here
        ListNode slow = A ;
        ListNode fast = A ;
        while (fast != null && fast.next != null) {
            slow = slow .next ;
            fast = fast.next.next ;
        }


        ListNode cur = slow.next ;
        while (cur != null) {
            ListNode curNext = cur.next ;
            cur.next = slow ;
            slow = cur ;
            cur = curNext ;
        }
        ListNode head = A ;
        while (head != slow) {
            if (slow.val != head.val) {
                return false ;
            }
            if(head.next == slow){
                return true ;
            }
            head = head.next ;
            slow = slow.next ;
        }
        return true ;

    }
}